// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.randomizedWorld.randomizedVehicleStory;

import zombie.core.Rand;
import zombie.iso.IsoChunk;
import zombie.iso.IsoDirections;
import zombie.iso.IsoGridSquare;
import zombie.iso.IsoMetaGrid;
import zombie.iso.Vector2;
import zombie.vehicles.BaseVehicle;

public final class RVSTrailerCrash extends RandomizedVehicleStoryBase {
    public RVSTrailerCrash() {
        this.name = "Trailer Crash";
        this.minZoneWidth = 5;
        this.minZoneHeight = 12;
        this.setChance(3);
    }

    @Override
    public void randomizeVehicleStory(IsoMetaGrid.Zone zone, IsoChunk chunk) {
        this.callVehicleStorySpawner(zone, chunk, 0.0F);
    }

    @Override
    public boolean initVehicleStorySpawner(IsoMetaGrid.Zone zone, IsoChunk chunk, boolean debug) {
        VehicleStorySpawner vehicleStorySpawner = VehicleStorySpawner.getInstance();
        vehicleStorySpawner.clear();
        float float0 = (float) (Math.PI / 6);
        if (debug) {
            float0 = 0.0F;
        }

        Vector2 vector2 = IsoDirections.N.ToVector();
        vector2.rotate(Rand.Next(-float0, float0));
        float float1 = 0.0F;
        float float2 = -1.5F;
        vehicleStorySpawner.addElement("vehicle1", float1, float2, vector2.getDirection(), 2.0F, 5.0F);
        byte _byte = 4;
        vehicleStorySpawner.addElement("trailer", float1, float2 + 2.5F + 1.0F + (float)_byte / 2.0F, vector2.getDirection(), 2.0F, (float)_byte);
        boolean _boolean = Rand.NextBool(2);
        vector2 = _boolean ? IsoDirections.E.ToVector() : IsoDirections.W.ToVector();
        vector2.rotate(Rand.Next(-float0, float0));
        float float3 = 0.0F;
        float float4 = float2 - 2.5F - 1.0F;
        vehicleStorySpawner.addElement("vehicle2", float3, float4, vector2.getDirection(), 2.0F, 5.0F);
        vehicleStorySpawner.setParameter("zone", zone);
        vehicleStorySpawner.setParameter("east", _boolean);
        return true;
    }

    @Override
    public void spawnElement(VehicleStorySpawner spawner, VehicleStorySpawner.Element element) {
        IsoGridSquare isoGridSquare = element.square;
        if (isoGridSquare != null) {
            float _float = element.z;
            IsoMetaGrid.Zone zone = spawner.getParameter("zone", IsoMetaGrid.Zone.class);
            boolean _boolean = spawner.getParameterBoolean("east");
            String string0 = element.id;
            switch (string0) {
                case "vehicle1":
                    BaseVehicle baseVehicle1 = this.addVehicle(
                        zone, element.position.x, element.position.y, _float, element.direction, null, "Base.PickUpVan", null, null
                    );
                    if (baseVehicle1 != null) {
                        baseVehicle1 = baseVehicle1.setSmashed("Front");
                        baseVehicle1.setBloodIntensity("Front", 1.0F);
                        String string2 = Rand.NextBool(2) ? "Base.Trailer" : "Base.TrailerCover";
                        if (Rand.NextBool(6)) {
                            string2 = "Base.TrailerAdvert";
                        }

                        BaseVehicle baseVehicle2 = this.addTrailer(baseVehicle1, zone, isoGridSquare.getChunk(), null, null, string2);
                        if (baseVehicle2 != null && Rand.NextBool(3)) {
                            baseVehicle2.setAngles(baseVehicle2.getAngleX(), Rand.Next(90.0F, 110.0F), baseVehicle2.getAngleZ());
                        }

                        if (Rand.Next(10) < 4) {
                            this.addZombiesOnVehicle(Rand.Next(2, 5), null, null, baseVehicle1);
                        }

                        spawner.setParameter("vehicle1", baseVehicle1);
                    }
                    break;
                case "vehicle2":
                    BaseVehicle baseVehicle0 = this.addVehicle(zone, element.position.x, element.position.y, _float, element.direction, "bad", null, null, null);
                    if (baseVehicle0 != null) {
                        String string1 = _boolean ? "Right" : "Left";
                        baseVehicle0 = baseVehicle0.setSmashed(string1);
                        baseVehicle0.setBloodIntensity(string1, 1.0F);
                        spawner.setParameter("vehicle2", baseVehicle0);
                    }
            }
        }
    }
}
